
import 'package:xim/common/util/datetime.dart';
import 'package:xim/common/util/security.dart';
import 'package:xim/common/util/sm2.dart';
import 'package:xim/config/store_config.dart';
import 'package:xim/http/apis/user/user_model.dart';

/// [java:SecretKeyVo]
class SessionSecretKeyModel {

  /// 密钥ID
  final int id;

  /// 加密后的ASE密钥
  String secretKey;

  /// 密钥创建者账号
  final String creatorAccount;

  /// 所在会话的密钥版本号
  final int secretKeyVersion;

  /// 会话Id
  final int sessionId;

  /// 创建时间
  final DateTime createTime;

  /// 创建者信息
  final UserInfoModel? creatorInfo;

  SessionSecretKeyModel({
    required this.id,
    required this.secretKey,
    required this.creatorAccount,
    required this.secretKeyVersion,
    required this.sessionId,
    required this.createTime,
    this.creatorInfo
  });

  Map<String, dynamic> toJson() =>{
    "id": id,
    "secretKey": secretKey,
    "creatorAccount": creatorAccount,
    "secretKeyVersion": secretKeyVersion,
    "sessionId": sessionId,
    "createTime": createTime.format("yyyy-MM-dd HH:mm:ss"),
    "creatorInfo": creatorInfo?.toJson(),
  };

  SessionSecretKeyModel.fromJson(Map<String, dynamic> json):
        id=json['id'],
        secretKey=json['secretKey'],
        creatorAccount=json['creatorAccount'],
        secretKeyVersion = json['secretKeyVersion'],
        sessionId=json['sessionId'],
        createTime= DateTime.parse(json['createTime']),
        creatorInfo= json['creatorInfo']!=null?UserInfoModel.fromJson(json['creatorInfo']):null
  ;

}